package com.cq.health.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.cq.health.common.MessageConst;
import com.cq.health.entity.Result;
import com.cq.health.pojo.Setmeal;
import com.cq.health.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: 悠久的苍穹
 * @Date: 2020/6/4 21:03
 * @Description: 移动端套餐组控制器
 * @Version: 1.0
 */
@RestController
@Slf4j
@RequestMapping("/mobile/setmeal")
public class SetmealController {
    @Reference
    private SetmealService setmealService;

    @RequestMapping("/getSetmeal")
    public Result getSetmeal(){
        try{
            log.debug("getSetmeal");
            List<Setmeal> list = setmealService.findAll();
            return new Result(true, MessageConst.QUERY_SETMEAL_SUCCESS,list);
        }catch(Exception e){
            e.printStackTrace();
            return new Result(false, MessageConst.QUERY_SETMEAL_FAIL);
        }
    }

    @RequestMapping("/findById")
    public Result findById(Integer id){
        try {
            Setmeal setmeal = setmealService.findById(id);
            return new Result(true, MessageConst.QUERY_SETMEAL_SUCCESS,setmeal);
        }catch (Exception e){
             e.printStackTrace();
            return new Result(false, MessageConst.QUERY_SETMEAL_FAIL);
        }
    }

}
